<?php

class Root_model extends CI_Model {


    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
	
	function hitung_data($field,$table)
	{
		$this->db->select($field);
		$hitung = $this->db->get($table);
		
		return $hitung->num_rows();
	}
	
	function get_single_data($select, $table, $fid, $id)
	{
		$this->db->select($select);
		$this->db->from($table);
		$this->db->where($fid, $id);
		$data = $this->db->get();
		
		foreach($data->result() AS $hasil)
		{
			return $hasil->$select;
		}
		
		return FALSE;
	}
	
	function get_kategori($awal=0)
	{
		$this->db->order_by('kategori', 'asc');
		$this->db->limit(10, $awal);
		$data = $this->db->get('dn_category');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_data_kategori($id=0)
	{
		$this->db->where('idkategori', $id);
		
		$data = $this->db->get('dn_category');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function set_kategori($data)
	{
		$this->db->insert('dn_category', $data);
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function update_kategori($data, $id=0)
	{
		$this->db->where('idkategori', $id);
		$this->db->update('dn_category', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function hapus_kategori($id=0)
	{
		$this->db->where('idkategori', $id);
		$this->db->delete('dn_category');
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
    
	function get_usaha($awal=0)
	{
		$this->db->order_by('idperusahaan', 'desc');
		$this->db->limit(10, $awal);
		
		$data = $this->db->get('dn_company');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_data_usaha($idp=0)
	{
		$this->db->where('idperusahaan', $idp);
		
		$data = $this->db->get('dn_company');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function cek_pemilik_usaha($idp, $uid)
	{
		$this->db->select('idperusahaan');
		$this->db->from('dn_company');
		$this->db->where('idperusahaan',$idp);
		$this->db->where('uid', $uid);
		
		$query = $this->db->get();
		if($query->num_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function set_usaha($data)
	{
		$this->db->insert('dn_company', $data);
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function update_usaha($data, $idp=0)
	{
		$this->db->where('idperusahaan', $idp);
		
		$this->db->update('dn_company', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function hapus_usaha($idp=0)
	{
		$this->db->where('idperusahaan', $idp);
		
		$this->db->delete('dn_company');
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
	
	
	function get_produk($awal=0)
	{
		$this->db->select('p.idproduk AS idproduk, p.nama AS nama, c.uid AS uid');
		$this->db->from('dn_product AS p');
		$this->db->join('dn_company AS c', 'p.idperusahaan=c.idperusahaan');
		$this->db->order_by('p.idproduk', 'desc');
		$this->db->limit(20, $awal);
		
		$data = $this->db->get();
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_data_produk($idp=0)
	{
		$this->db->where('idproduk', $idp);
		
		$data = $this->db->get('dn_product');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_edit_data_produk($idp, $uid)
	{
		$this->db->select('p.idproduk AS idproduk, p.idperusahaan AS idperusahaan, p.nama AS nama, p.deskripsi AS deskripsi, p.gambar AS gambar')->from('dn_product AS p')->join('dn_company AS c','p.idperusahaan=c.idperusahaan');
		$this->db->where('p.idproduk', $idp);
		$this->db->where('c.uid', $uid);
		
		$query = $this->db->get();	
		if($query->num_rows() > 0)
		{
			return $query->result();
		}
		return FALSE;
	}
	
	function cek_pemilik_produk($idp=0, $uid=0)
	{
		$this->db->select('p.idproduk');
		$this->db->from('dn_product AS p');
		$this->db->join('dn_company AS q', 'p.idperusahaan=q.idperusahaan');
		$this->db->where('p.idproduk', $pid);
		$this->db->where('q.uid', $uid);
		
		$query = $this->db->get();
		if($query->num_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function set_produk($data)
	{
		$this->db->insert('dn_product', $data);
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function update_produk($data, $idp=0)
	{
		$this->db->where('idproduk', $idp);
		$this->db->update('dn_product', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function hapus_produk($idp=0)
	{
		$this->db->where('idproduk', $idp);
		$this->db->delete('dn_product');
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
	
	function get_loker($awal=0)
	{
		$this->db->select('j.idjob AS idjob, j.posisi AS posisi, j.berakhir AS berakhir, c.uid AS uid');
		$this->db->from('dn_job AS j');
		$this->db->join('dn_company AS c', 'j.idperusahaan=c.idperusahaan');
		$this->db->order_by('j.idjob', 'desc');
		$this->db->limit(10, $awal);
		
		$data = $this->db->get();
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_data_loker($idj=0)
	{
		$this->db->where('idjob', $idj);
		
		$data = $this->db->get('dn_job');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_edit_data_loker($idj, $uid)
	{
		$this->db->select('j.idjob, j.idperusahaan, j.posisi, j.deskripsi, j.cara, j.tipe, j.lokasi, j.gambar, j.berakhir')->from('dn_job AS j')->join('dn_company AS c','j.idperusahaan=c.idperusahaan');
		$this->db->where('j.idjob',$idj);
		$this->db->where('c.uid',$uid);
		
		$query = $this->db->get();	
		if($query->num_rows() > 0)
		{
			return $query->result();
		}
		return FALSE;
	}
	
	function cek_pemilik_loker($idj, $uid)
	{
		$this->db->select('j.idjob');
		$this->db->from('dn_job AS j');
		$this->db->join('dn_company AS p', 'j.idperusahaan=p.idperusahaan');
		$this->db->where('j.idjob',$idj);
		$this->db->where('p.uid',$uid);
		
		$query = $this->db->get();
		if($query->num_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function set_loker($data)
	{
		$this->db->insert('dn_job', $data);
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function update_loker($data, $idj=0)
	{
		$this->db->where('idjob', $idj);
		$this->db->update('dn_job', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function hapus_loker($idj=0)
	{
		$this->db->where('idjob', $idp);
		$this->db->delete('dn_job');
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
	
	function get_acara($awal=0)
	{
		$this->db->order_by('idacara', 'desc');
		$this->db->limit(10, $awal);
		$data = $this->db->get('dn_event');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_data_acara($ida=0)
	{
		$this->db->where('idacara', $ida);
		
		$data = $this->db->get('dn_event');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_edit_data_acara($ida=0, $uid=0)
	{
		$this->db->where('idacara', $ida);
		$this->db->where('uid', $uid);
		
		$data = $this->db->get('dn_event');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function set_acara($data)
	{
		$this->db->insert('dn_event', $data);
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function update_acara($data, $ida=0, $uid=0)
	{
		$this->db->where('idacara', $ida);
		$this->db->where('uid', $uid);
		
		$this->db->update('dn_event', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function hapus_acara($ida=0, $uid=0)
	{
		$this->db->where('idacara', $ida);
		$this->db->where('uid', $uid);
		
		$this->db->delete('dn_event');
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
	
	function get_pengguna($awal=0)
	{
		$this->db->limit(10, $awal);
		$data = $this->db->get('dn_users');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_data_pengguna($uid = 0)
	{
		$this->db->where('uid', $uid);
		
		$data = $this->db->get('dn_users');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function set_pengguna($data)
	{
		$this->db->insert('dn_users', $data);
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function update_pengguna($data, $uid=0)
	{
		$this->db->where('uid', $uid);
		$this->db->update('dn_users', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function hapus_pengguna($uid=0)
	{
		$this->db->where('uid', $uid);
		$this->db->delete('dn_users');
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
	
	function get_scn($awal=0)
	{
		$this->db->order_by('idperusahaan', 'desc');
		$this->db->limit(10, $awal);
		$data = $this->db->get('dn_company');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_data_scn($idp=0)
	{
		$this->db->where('idperusahaan', $idp);
		
		$data = $this->db->get('dn_company');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function set_scn($data)
	{
		$this->db->insert('dn_company', $data);
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function update_scn($data, $idp=0)
	{
		$this->db->where('idperusahaan', $idp);
		$this->db->update('dn_company', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function hapus_scn($idp=0)
	{
		$this->db->where('idperusahaan', $idp);
		$this->db->delete('dn_company');
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
	

	
	function get_masukan($awal=0)
	{
		$this->db->order_by('id', 'desc');
		$this->db->limit(10, $awal);
		$data = $this->db->get('dn_feedback');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_data_masukan($id=0)
	{
		$this->db->where('id', $id);
		
		$data = $this->db->get('dn_feedback');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function hapus_masukan($id=0)
	{
		$this->db->where('id', $id);
		$this->db->delete('dn_feedback');
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
	
	function get_lapor($awal=0)
	{
		$this->db->order_by('idlaporan', 'desc');
		$this->db->limit(10, $awal);
		
		$data = $this->db->get('dn_report');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_data_lapor($id=0)
	{
		$this->db->where('idlaporan', $id);
		
		$data = $this->db->get('dn_report');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function hapus_lapor($id=0)
	{
		$this->db->where('idlaporan', $id);
		$this->db->delete('dn_report');
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
	
	function get_social_network($uid=0)
	{
		$this->db->where('uid', $uid);
		$hasil = $this->db->get('dn_social');
		
		if($hasil->num_rows() > 0)
		{
			return $hasil->result();
		}
		
		return FALSE;
	}
	
	function cek_social_network($uid=0, $sc)
	{
		$this->db->where('uid', $uid);
		$this->db->where('app', $sc);
		$hasil = $this->db->get('dn_social');
		
		if($hasil->num_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function cek_social_network_id($sc, $sid)
	{
		
		$this->db->where('app', $sc);
		$this->db->where('sid', $sid);
		$hasil = $this->db->get('dn_social');
		
		if($hasil->num_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function set_social_network($uid=0, $sc, $sid)
	{
		$data = array('uid' => $uid, 'app' => $sc, 'sid' => $sid);
		$this->db->insert('dn_social', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function update_social_network($uid, $sc, $sid)
	{
		$data = array('sid' => $sid);
		
		$this->db->where('uid', $uid);
		$this->db->where('app', $sc);
		$this->db->update('dn_social', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function get_testimoni($idp=0, $awal=0)
	{
		$this->db->where('idperusahaan', $idp);
		$this->db->order_by('idtestimoni', 'desc');
		$this->db->limit(10, $awal);
		$data = $this->db->get('dn_testimoni');
		
		if($this->db->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function set_testimoni($data)
	{
		$this->db->insert('dn_testimoni', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	} 
	
	
	/*	tambahan	*/
	
	function get_daftar_kategori()
	{
		$this->db->order_by('kategori', 'asc');
		$data = $this->db->get('dn_category');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_daftar_usaha()
	{
		$this->db->order_by('nama', 'asc');
		$data = $this->db->get('dn_company');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_usaha_user($uid=0)
	{
		$this->db->where('uid', $uid);
		$this->db->order_by('nama', 'asc');
		$data = $this->db->get('dn_company');
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function cek_user_name($username)
	{
		$this->db->where('username', $username);
		$hasil = $this->db->get('dn_users');
		if($hasil->num_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function cek_user_password($uid, $password)
	{
		$this->db->where('uid', $uid);
		$this->db->where('password', $password);
		
		$hasil = $this->db->get('dn_users');
		if($hasil->num_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	/*	end tambahan	*/
    
    
    
	
	
    
}

/* End of file admin_model.php */
/* Location: ./application/models/admin_model.php */
